<template>
  <div class="buyticket">
    <!-- 头部 -->
    <div class="maoyan">
      <div class="maoyan-l iconfont icon-fanhui" @click="$router.back()">
        <!-- <img src="../assets/返回白.png" alt="" /> -->
      </div>
      <div class="maoyan-c">{{ movies.nm }}</div>
      <div class="maoyan-r"></div>
    </div>

    <!-- 影片详情 -->
    <div class="detail" :style="`background:${movies.backgroundColor}`">
      <img class="img" :src="movies.img" alt="" />
      <div class="content">
        <div class="title">{{ movies.nm }}</div>
        <div class="pubilc">{{ movies.enm }}</div>
        <div class="score">
          <span class="sc">{{ movies.sc }}</span>
          <span class="snum">({{ movies.snum  }}人评)</span>
        </div>
        <div class="type">
          <span class="cat">{{ movies.cat }}</span>
          <span class="type-img" v-show="movies.multiPub"></span>
        </div>
        <div class="line">{{ movies.src }}/{{ movies.dur }}分钟</div>
        <div class="line-e">{{ movies.pubDesc }}</div>
      </div>
      <div class="bg"></div>
    </div>

    <!-- 日期列表 -->
    <van-tabs
      @click="onClick"
      line-height="1.5px"
      line-width="74px"
      title-active-color="red"
    >
      <van-tab v-for="(n, i) in dates" :key="i" :title="n.date "></van-tab>
    </van-tabs>

    <!-- 影院列表 -->
    
    <div class="cinemas" >
      <div
        class="item"
        v-for="item in cinemas"
        :key="item.id"
        @click="tickets(item)"
      >
        <div class="titles">
          <div class="titles-t">{{ item.name }}</div>
          <div class="prices">
            <span class="pr">{{ item.sellPrice }}</span>
            <span class="ice">元起</span>
          </div>
        </div>
        <div class="linee">
          <div class="linee-e">{{ item.addr }}</div>
          <div class="di">{{ item.distance }}</div>
        </div>
        <div class="lab">
          <div
            v-for="(n, i) in item.labels"
            :key="i"
            :style="`color:${n.color}; border:1px solid ${n.color};`"
          >
            {{ n.name }}
          </div>
        </div>
        <div class="div" v-show="item.promotion.cardPromotionTag">
          <div class="imgka"></div>
          <div class="text">{{ item.promotion.cardPromotionTag }}</div>
        </div>
        <div class="recent">{{ item.showTimes }}</div>
      </div>
    </div>

    <!-- 点击影院进入购票处 -->
    <!-- <TicketOffice
      v-show="ticket"
      @ticket-f="$store.state.ticket = false"
      :cinema="cinema"
    /> -->
  </div>
</template>

<script>
// 引入特定影院购票
// import TicketOffice from "@/components/TicketOffice.vue";



import { Toast } from "vant";

export default {
  components: {
    // TicketOffice,
  },
 
  data: function () {
    return {
      movies: [], //影片详情
      dates: [], //日期
      cinemas: [], //影院列表
      time:"",
      loading:true,
      cityname:[],
    };
  },
  methods: {
    NowTime: function () {
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      if (month < 10) {
        month = "0" + month;
      }
      if (day < 10) {
        day = "0" + day;
      }
      return year + "-" + month + "-" + day;
    },
    getHistory() {
      //获取历史记录
      let re = localStorage.getItem("selecthistory");
      this.cityname = JSON.parse(re)[0];
    },
    // 点击特定的时间赋值
    onClick(name, title) {
      Toast(title);
      console.log(title);
      this.$store.state.time = title;
      console.log(this.$store.state.time);
    },
    // 点击跳转购票页面
    tickets: function (n) {
      this.$router.push({
        path: "/ticketoffice",
        query: {
          cinemaId: n.id,
          addr: n.addr,
          movieId: this.$route.query.id,
          date: this.time,
        },
      });
    },
  },
  created: function () {
    this.getHistory();
   this.time = this.NowTime();
    //影片数据链接
    this.axios
      .get(
        "https://apis.netstart.cn/maoyan/movie/intro?movieId=" +
          this.$route.query.id +
          ""
      )
      .then((res) => {
        this.movies = res.data.data.movie;
        // console.log(res, this.movies, this.time);
      });

    //获取日期链接
    this.axios
      .get(
        "https://apis.netstart.cn/maoyan/movie/showdays?movieId=" +
          this.$route.query.id +
          "&cityId=" +
          this.cityname.id +
          ""
      )
      .then((res) => {
        this.dates = res.data.data.dates;
        console.log(res.data, this.dates);
      });

    // 默认显示当天影院详情
    this.$store.state.loading = true;
    this.axios
      .get(
        "https://apis.netstart.cn/maoyan/movie/select/cinemas?limit=20&offset=0&client=iphone&channelId=4&showDate=" +
          this.time +
          "&movieId=" +
          this.$route.query.id +
          "&sort=distance&cityId=" +
          this.cityname.id +
          "&lat=23.135610180010865&lng=113.42416693422547&districtId=-1&lineId=-1&areaId=-1&stationId=-1&brandIds=%5B-1%5D&serviceIds=%5B-1%5D&hallTypeIds=%5B%22all%22%5D&languageIds=%5B%22all%22%5D&dimIds=%5B%22all%22%5D"
      )
      .then((res) => {
        this.cinemas = res.data.data.cinemas;
        console.log(res, this.cinemas);
        this.$store.state.loading = false;
      });
  },
  watch: {
    // 监听日期变化获取影院数据
    time: function () {
      this.$store.state.loading = true;
      this.axios
        .get(
          "https://apis.netstart.cn/maoyan/movie/select/cinemas?limit=20&offset=0&client=iphone&channelId=4&showDate=" +
            this.time +
            "&movieId=" +
            this.$route.query.id +
            "&sort=distance&cityId=" +
            this.cityname.id +
            "&lat=23.135610180010865&lng=113.42416693422547&districtId=-1&lineId=-1&areaId=-1&stationId=-1&brandIds=%5B-1%5D&serviceIds=%5B-1%5D&hallTypeIds=%5B%22all%22%5D&languageIds=%5B%22all%22%5D&dimIds=%5B%22all%22%5D"
        )
        .then((res) => {
          this.cinemas = res.data.data.cinemas;
          // console.log(res, this.cinemas);
          this.$store.state.loading = false;
        });
    },
  },
};
</script>

<style lang="less" scoped>
.buyticket {
  .maoyan {
    padding: 6px;
    background-color: #e54847;
    height: 38px;
    width: 363px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .maoyan-l {
      width: 100px;
      height: 38px;
    }
    .icon-fanhui {
      font-size: 22px;
      color: #ffffff;
      margin-top: 13px;
      margin-left: 3px;
    }

    .maoyan-c {
      font-size: 18px;
      color: #fff;
      width: 163px;
      height: 38px;
      text-align: center;
      line-height: 38px;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }

    .maoyan-r {
      width: 100px;
      height: 38px;
    }
  }

  .detail {
    display: flex;
    align-items: center;
    padding: 19px 30px 19px 15px;
    position: relative;

    .img {
      width: 110px;
      height: 150px;
    }
    .content {
      margin-left: 12.5px;
      color: #ffffff;

      .title {
        margin-top: 2px;
        font-size: 20px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        font-weight: 700;
      }
      .pubilc {
        margin-top: 10px;
        opacity: 0.8;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        font-size: 12px;
      }
      .score {
        .sc {
          font-size: 18px;
          font-weight: 700;
          color: #fc0;
        }
        .snum {
          display: inline-block;
          margin-left: 5px;
          font-size: 12px;
          color: #fff;
          opacity: 0.8;
        }
      }
      .type {
        display: flex;
        align-items: center;
        .cat {
          font-size: 12px;
        }
        .type-img {
          display: inline-block;
          width: 26px;
          height: 13px;
          margin-left: 5px;
          background: url("../assets/max.png") no-repeat;
          background-size: cover;
        }
      }
      .line {
        margin-top: 10px;
        font-size: 12px;
      }
      .line-e {
        margin-top: 10px;
        font-size: 12px;
      }
    }
    .bg {
      position: absolute;
      right: 10px;
      top: 45%;
      width: 10px;
      height: 14.6px;
      background: url("../assets/向右.png") no-repeat;
      background-size: cover;
    }
  }

  .cinemas {
    .item {
      padding: 13px 15px 13px 0;
      margin-left: 15px;
      border-bottom: 1px solid rgb(233, 230, 230);
      .titles {
        display: flex;
        height: 27px;
        .titles-t {
          flex: 1;
          height: 23px;
          line-height: 23px;
          font-size: 16px;
          color: #000;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
        }
        .prices {
          padding-left: 3px;
          color: #f03d37;
          .pr {
            font-size: 18px;
          }
          .ice {
            padding-left: 3px;
            font-size: 11px;
          }
        }
      }
      .linee {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 13px;
        color: #666;
        .linee-e {
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
        }
        .di {
        }
      }
      .lab {
        display: flex;
        margin: 4px 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        height: 18px;
        div {
          padding: 0 3px;
          margin-left: 3px;
          border-radius: 4px;
          font-size: 12px;

          &:nth-child(1) {
            margin: 0;
          }
        }
      }
      .div {
        display: flex;
        align-items: center;
        .imgka {
          width: 15px;
          height: 14px;
          margin-right: 3px;
          background: url("../assets/ka.png") no-repeat;
          background-size: cover;
        }
        .text {
          font-size: 12px;
          color: #999999;
        }
      }
      .recent {
        padding: 0 15px 0 0;
        margin-right: -15px;
        line-height: 1.5;
        font-size: 12px;
      }
    }
  }
}
</style>